package com.us.usws.service.cud.impl;

import org.apache.commons.lang3.StringUtils;

import com.us.usws.common.SiteConstants;
import com.us.usws.dao.UserDAO;
import com.us.usws.model.domain.system.User;
import com.us.usws.service.cud.UserCUDService;

public class UserCUDServiceImpl implements UserCUDService {

	private UserDAO dao = new UserDAO();

	@Override
	public String add(User user) {
		return dao.insertUser(user);
	}

	@Override
	public void update(User user) {
		dao.update(user);
	}

	@Override
	public void hardDelete(String uid) {
		dao.deleteUser(uid);
	}

	@Override
	public void delete(String uid) {
		dao.updateValid(uid, SiteConstants.STR_BOOLEAN_NO);
	}

	@Override
	public void deleteMore(String uids) {
		/*
		 * support more delete
		 */
		if (StringUtils.isNotBlank(uids)) {
			String[] uid = StringUtils.split(uids, ",");
			for (String id : uid) {
				delete(id);
			}
		}
	}

	@Override
	public void undelete(String uid) {
		dao.updateValid(uid, SiteConstants.STR_BOOLEAN_YES);
	}

	@Override
	public void updateAvatar(String uid, String avatar) {
		dao.updateAvatar(uid, avatar);
	}

	@Override
	public void updatePassword(String newPasswd, String userUid) {
		dao.updatePassword(newPasswd, userUid);
	}

}
